/* SPX.do (STATA)
	Construct SPX data.
	by Ralph Koijen & Motohiro Yogo */

#delimit ;
clear all;
set more off;
set type double;

cap log close;
log using SPX, replace;

/* Define local and global variables */

local directory = "../../Data_nonpublic/Global Financial Data";

do global;


/* Load data */

import excel using "`directory'/SPX",
	sheet("Price Data") first clear;

drop _SPXD;

/* Rename variables */

rename SYSPXMBM mb;

/* Construct variables */

gen int year = year(date(Date,"MDY"));

drop Date;

/* Construct log varialbes */

gen Lmb = ln(mb);

/* Construct returns */

sort year;

gen _ret = ln(_SPXTRD[_n+1]/_SPXTRD);

drop _SPXTRD;

/* Sample criteria */

keep if year<=$year_max;

/* Label variables */

order year;

label var year	"Year";

label var mb	"Market-to-book equity";
label var Lmb	"Log market-to-book equity";
label var _ret	"Future: Return (continuously compounded)";

/* Save data */

sort year;

save SPX, replace;

log close;
